package adminServlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import specifications.CitySpecification;
import adminejb.CityBeanLocal;

/**
 * Servlet implementation class deleteCity
 */
@WebServlet("/deleteCity")
public class deleteCity extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public deleteCity() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    @EJB
    CityBeanLocal cityBean;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    	String citycode = request.getParameter("citycode");
    	    	
    	cityBean.deleteCity(citycode);
    	response.setContentType("text/html;charset=UTF-8");
    	PrintWriter out;
		try {
			out = response.getWriter();
			printPageStart(out);
            out.println("<h4>City " + citycode + " deleted!</h4>");
            out.println("<a class='btn btn-default' href='../../../NCProjectWeb/admin/index.jsp' role='button'>Home</a>");
            out.println("<a class='btn btn-default' href='getParamsToShowAllCities' role='button'>Show All</a>");
            printPageEnd(out);			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
private void printPageStart(PrintWriter out) {
        
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Review City</title>");        
        out.println("<link href='../../../NCProjectWeb/css/bootstrap.css' rel='stylesheet'>");
        out.println("<link href='../../../NCProjectWeb/css/bodystyle.css' rel='stylesheet'>");
        out.println("</head>");
        out.println("<body>");
        
    }
    
    private void printPageEnd(PrintWriter out) {
        
        out.println("</body>");
        out.println("</html>");
        out.close();
    }
    

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
